#!/bin/bash
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

set -e -o pipefail

REPO_PATH="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"

# Some native modules want to compile stuff. Limit concurrency to prevent too
# high load spikes on the CI servers.
# Keep in sync with omd/packages/python3-modules/build-python3-modules.bzl
if [ "$CI" == "true" ]; then
    export \
        GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS=4 \
        NPY_NUM_BUILD_JOBS=4
fi

# Avoid a loop when building the virtual environment itself.
if [ -z "$SKIP_MAKEFILE_CALL" ]; then
    make --silent -C "$REPO_PATH" .venv 1>&2
fi

# shellcheck source=/dev/null
source "${REPO_PATH}/.venv/bin/activate"
"$@"
deactivate
